/*
 * Copyright (c) 2022. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
 * Morbi non lorem porttitor neque feugiat blandit. Ut vitae ipsum eget quam lacinia accumsan.
 * Etiam sed turpis ac ipsum condimentum fringilla. Maecenas magna.
 * Proin dapibus sapien vel ante. Aliquam erat volutpat. Pellentesque sagittis ligula eget metus.
 * Vestibulum commodo. Ut rhoncus gravida arcu.
 */

package com.tarry.singleton;

import java.io.*;
import java.util.Objects;

public class SingletonMain {
    public static void main(String[] args) throws IOException, ClassNotFoundException {

        ConfigEntity config = EnumSingleton.INSTANCE.getInstance();
        ConfigEntity config2 = EnumSingleton.INSTANCE.getInstance();
        System.out.println(Objects.equals(config, config2));

        final String fileName = "configEntity.obj";

        FileOutputStream fos = new FileOutputStream(fileName);
        ObjectOutputStream outputStream = new ObjectOutputStream(fos);
        outputStream.writeObject(config);
        fos.close();
        outputStream.close();

        FileInputStream fis = new FileInputStream(fileName);
        ObjectInputStream inputStream = new ObjectInputStream(fis);
        ConfigEntity cloneConfigObj = (ConfigEntity) inputStream.readObject();
        fis.close();
        inputStream.close();
        System.out.println(Objects.equals(config, cloneConfigObj));

    }
}
